package com.zhaojonhy.zhaopangwb.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.zhaojonhy.zhaopangwb.R;
import com.zhaojonhy.zhaopangwb.utils.EmojiUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/29.
 */

public class EmotionGvAdapter extends BaseAdapter {
    private Context context ;
    private List<String> emojiNames ;
    private int itemWidth ;
    public EmotionGvAdapter( Context context , List<String> emojiNames , int itemWidth ) {
        this.context = context ;
        this.emojiNames = emojiNames ;
        this.itemWidth = itemWidth ;
    }

    @Override
    public int getCount() {
        return emojiNames.size() + 1 ; //多一个做退格键
    }

    @Override
    public String  getItem(int position) {
        return emojiNames.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(context) ;
        LayoutParams params = new LayoutParams(itemWidth,itemWidth) ;
        imageView.setPadding(itemWidth/8,itemWidth/8,itemWidth/8,itemWidth/8);
        imageView.setLayoutParams(params);
        imageView.setBackgroundResource(R.drawable.bg_tran2gray_sel);

        if( position == getCount() - 1 ) {
            imageView.setImageResource(R.drawable.emotion_delete_icon);
        }else {
            String emojiName = emojiNames.get(position) ;
            imageView.setImageResource(EmojiUtils.getImgByName(emojiName));
        }
        return imageView;
    }
}
